/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


function closeAllSubMenu() {
    if (document.getElementById('mainMenu') == null)
        return;
    var arrayDiv = document.getElementById('mainMenu').getElementsByTagName('div');
    arrayLI = document.getElementById('mainMenu').getElementsByTagName('li');
    for (i = 0; i < arrayDiv.length; i++)
        arrayDiv[i].style.visibility = 'hidden';
    for (i = 0; i < arrayLI.length; i++)
        arrayLI[i].className = 'none';
}

function searchDIV(nameDiv) {
    var arrayDiv = document.getElementsByTagName('div');
    i = 0;
    while ((i < arrayDiv.length) && (arrayDiv[i].className != nameDiv))
        i++;
    return arrayDiv[i];
}

function widthDIV(nameDiv) {
    return searchDIV(nameDiv).offsetWidth;
}


function searchCSSName(nameCSS) {
    rul = document.styleSheets[0].rules;
    i = 0;
    if (rul == null)
        return (null);
    while ((i < rul.length) && (rul[i].selectorText != nameCSS))
        i++;
    if ((i != rul.length) && (rul[i].selectorText == nameCSS))
        return(rul[i]);
    return(null);
}

function displaySubMenu(itemName, subName) {
    closeAllSubMenu();
    $('#' + subName + '').css('visibility', 'visible');
    $('#' + itemName + '').addClass('chosen');

    if (document.getElementById(subName).style.left == '')
    {
        if (document.getElementById(searchDIV('mainMenu').className) != null)
        {
            leftPosition_Submenu = (document.getElementById(itemName).offsetLeft
                    + document.getElementById(itemName).offsetWidth / 2)
                    - document.getElementById(subName).offsetWidth / 2;
            widthMenu = widthDIV('mainMenu');
            if ((leftPosition_Submenu + document.getElementById(subName).offsetWidth) > widthMenu)
                document.getElementById(subName).style.left = widthMenu
                        - document.getElementById(subName).offsetWidth + 'px';
            else if (leftPosition_Submenu < 0)
                document.getElementById(subName).style.left = 0 + 'px'
            else
                document.getElementById(subName).style.left = leftPosition_Submenu + 'px';
        }
    }
    if ((document.styleSheets) && ((css = searchCSSName('.mainSubMenu_exp')) != null))
        document.getElementById(subName).style.marginTop = css.style.marginTop;
}

function hideSubMenu(itemName, subName) {
    $('#' + subName + '').css('visibility', 'hidden');
    if ($('#' + itemName + '').hasClass('chosen'))
        $('#' + itemName + '').removeClass('chosen');
}
